/*
 * 文件名：LocalTimerServiceImpl.java	 
 * 时     间：下午5:33:44
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.local.dao.mapers.LocalTimerMapper;
import com.local.model.LocalTimer;
import com.local.model.LocalTimerExample;
import com.local.service.face.LocalTimerService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.Tools;
import com.qianhai.common.utils.UUIDGenerateUtil;

/** 
 * 类描述:这里是类描述
 * @ClassName: LocalTimerServiceImpl 
 * @author Administrator
 * @date 2016年3月11日 下午5:33:44 
 */

@Service
public class LocalTimerServiceImpl extends BaseServiceImpl<LocalTimerExample, LocalTimer, String> implements LocalTimerService
{
	@Autowired
	private LocalTimerMapper localTimerMapper;
	
	@Override
	public LocalTimer loadLocalTimerInfo()
	{
		// TODO Auto-generated method stub
		LocalTimer lm=localTimerMapper.queryTimerInfo();
		if(!Tools.isEmpty(lm)){
			return lm;
		}
		return null;
	}

	@Override
	public BaseMapper<LocalTimerExample, LocalTimer, String> getMapper()
	{
		// TODO Auto-generated method stub
		return localTimerMapper;
	}

	@Override
	public Integer modifyTimerInfo(LocalTimer localTimer)
	{
		// TODO Auto-generated method stub
		try
		{
			if(!Tools.isEmpty(localTimer)&&!Tools.isEmpty(localTimer.getUuid())){
				if(Tools.isEmpty(localTimer.getCarInDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				if(Tools.isEmpty(localTimer.getCarOutDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				if(Tools.isEmpty(localTimer.getCarInHistoryDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				if(Tools.isEmpty(localTimer.getCarOutHistoryDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				localTimerMapper.updateByPrimaryKeySelective(localTimer);
				return 1;
			}else{
				localTimer.setUuid(UUIDGenerateUtil.generate());
				if(Tools.isEmpty(localTimer.getCarInDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				if(Tools.isEmpty(localTimer.getCarOutDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				if(Tools.isEmpty(localTimer.getCarInHistoryDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				if(Tools.isEmpty(localTimer.getCarOutHistoryDays())){
					throw new BaseException("50000-00001-00065"); 
				}
				localTimerMapper.insertSelective(localTimer);
				return 1;
			}
		} catch (Throwable t)
		{
			// TODO: handle exception
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
	}
	
}
